# -*- coding: utf-8 -*-
# @Time : 2019/1/14 11:52
# @Author : Administrator
# @File : util.py
# @Project : code
# @title : 工具：1、数据读取
import xlrd

class ExcelUtil():
    def __init__(self, excelPath, sheetName):
        self.data = xlrd.open_workbook(excelPath)
        self.table = self.data.sheet_by_name(sheetName)

        self.row = self.table.row_values(0)   #获取键名
        self.rowNum = self.table.nrows   #获取行数
        self.colNum = self.table.ncols   #获取列数
        self.curRowNo = 1   #当前行数为1

    def next(self):
        r = []
        while self.hasNext():
            s = {}
            col = self.table.row_values(self.curRowNo)
            i = self.colNum
            for x in range(i):
                s[self.row[x]] = col[x]
            r.append(s)
            self.curRowNo +=1
        return r

    def hasNext(self):
        if self.rowNum == 0 or self.rowNum <=self.curRowNo:
            return False
        else:
            return True


if __name__ == '__main__':
    excel = ExcelUtil(r'D:\wyq\第三阶段\code\boss_test\data.xls', 'add_data')
    data = excel.next()
    print(data)
